import math
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams

# 设置中文字体
rcParams['font.sans-serif'] = ['SimHei']
rcParams['axes.unicode_minus'] = False

# 将角度转换为弧度再进行计算
a_rad = math.radians(25)
b_rad = math.radians(40)

AandB = (a_rad + b_rad)
AdelB = (a_rad - b_rad)

# 计算单个角度的三角函数值
sin_a = math.sin(a_rad)
cos_a = math.cos(a_rad)
sin_b = math.sin(b_rad)
cos_b = math.cos(b_rad)
sin_AandB = math.sin(AandB)
cos_AandB = math.cos(AandB)
sin_AdelB = math.sin(AdelB)
cos_AdelB = math.cos(AdelB)

# 定义一个极小的数用于浮点数比较
epsilon = 1e-10

print("验证sin(a)cos(B)", '-' *40)
print(f"sin(a)cos(b) = {(sin_a * cos_b):.6f}")
print(f"(1/2)*[sin_AandB + sin_AdelB] = {(1/2)*(sin_AandB + sin_AdelB):.6f}")
print(f"sin(a)cos(b) = (1/2)*[sin_AandB + sin_AdelB] is {abs(sin_a * cos_b - (1/2)*(sin_AandB + sin_AdelB)) < epsilon}")

print("验证cos(a)sin(B)", '-' *40)
print(f"cos(a)sin(b) = {(cos_a * sin_b):.6f}")
print(f"(1/2)*[sin_AandB - sin_AdelB] = {(1/2)*(sin_AandB - sin_AdelB):.6f}")
print(f"cos(a)sin(b) = (1/2)*[sin_AandB - sin_AdelB] is {abs(cos_a * sin_b - (1/2)*(sin_AandB - sin_AdelB)) < epsilon}")

print("验证cos(a)cos(B)", '-' *40)
print(f"cos(a)cos(b) = {(cos_a * cos_b):.6f}")
print(f"(1/2)*[cos_AandB + cos_AdelB] = {(1/2)*(cos_AandB + cos_AdelB):.6f}")
print(f"cos(a)cos(b) = (1/2)*[cos_AandB + cos_AdelB] is {abs(cos_a * cos_b - (1/2)*(cos_AandB + cos_AdelB)) < epsilon}")

print("验证sin(a)sin(b)", '-' *40)
print(f"sin(a)sin(b) = {(sin_a * sin_b):.6f}")
print(f"-(1/2)*[cos_AandB - cos_AdelB] = {-(1/2)*(cos_AandB - cos_AdelB):.6f}")
print(f"sin(a)sin(b) = (1/2)*[cos_AandB - cos_AdelB] is {abs(sin_a * sin_b + (1/2)*(cos_AandB - cos_AdelB)) < epsilon}")
